home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000207_icon-group-sender _Mon Aug 15 14:30:52 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
2KB
Received: by cheltenham.cs.arizona.edu; Mon, 15 Aug 1994 15:31:07 MST
Date: Mon, 15 Aug 1994 14:30:52 +0700
From: swampler@noao.edu
Message-Id: <9408152130.AA22645@orpheus.gemini.edu>
Subject: Re: Generators
To: icon-group@cs.arizona.edu
Content-Length: 1261
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
espie@ens.fr wrote:
>>In Icon, you differentiate the other way. The implicit state differentiates
>>where the function was called. If you want an expression that can be resumed
>>elsewhere, you encapsulate it into a coexpression. Here is the classic
>>`build identifiers on the fly' in Icon.
>>procedure newid
>> i := 0
>> repeat
>> {
>> i +:= 1
>> suspend "a"||i
>> }
>>end
>>
>>called thus:
>>gen := create newid()
>>id:= @gen
>>each time you wish for a new id.
Just to extend Mark's explanation a bit - there is no requirement that the
expression 'encapsulated' by a coexpression consist of just a function call,
one may capture *any* Icon expression. So an alternative 'build identifiers
on the fly' implementation is simply:
gen := create "a"||seq()
since seq() is a function whose default behavior matches that
provided by the counter in Mark's newid() procedure. If gen is a global
variable, then @gen will produce the next 'id' whenever and wherever it
is invoked.
More on 'seq()' - it produces an infinite sequence of results on demand:
{1,2,3...}
though you can provide arguments to set both the initial value and the step
size, so
seq(2,2) produces {2,4,6,8,...}
--
Steve Wampler
swampler@gemini.edu
Gemini Project (under AURA)